package com.douqu.game.main.server.entity;

import com.bean.core.util.TimeUtils;
import com.douqu.game.core.e.E_ServerTaskType;
import com.douqu.game.core.factory.DataFactory;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-10-25 18:57
 */
public class ServerTask {

    private int id;

    private E_ServerTaskType type;

    private long startTime;

    public ServerTask(int id) {
        this.id = id;
    }

    public ServerTask(int id, E_ServerTaskType type, long startTime)
    {
        this.id = id;
        this.type = type;
        this.startTime = startTime;
    }

    public boolean isTimeout()
    {
        if(DataFactory.currentTime == 0)
            return System.currentTimeMillis() >= startTime;

        return DataFactory.currentTime >= startTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public E_ServerTaskType getType() {
        return type;
    }

    public void setType(E_ServerTaskType type) {
        this.type = type;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ServerTask)) return false;

        ServerTask that = (ServerTask) o;

        if (id != that.id) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public String toString() {
        return "{" +
                "id=" + id +
                ", type=" + type +
                ", startTime=" + TimeUtils.getFormatTime(startTime) +
                '}';
    }
}
